unit uConfirmaRec;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uPai_new, Menus, DB, StdCtrls, Buttons, ExtCtrls, MMJPanel, DateUtils;

type
  TfConfirmaRec = class(TfPai_new)
    Label1: TLabel;
    edEtiqueta: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    edProduto: TEdit;
    edOfDet: TEdit;
    edOf: TEdit;
    edProdDescri: TEdit;
    procedure btnGravarClick(Sender: TObject);
    procedure btnProcurarClick(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure edProdutoExit(Sender: TObject);
  private
    Procedure ConsultaBase(sql: string);
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fConfirmaRec: TfConfirmaRec;

implementation

uses udm;

{$R *.dfm}

procedure TfConfirmaRec.btnGravarClick(Sender: TObject);
var str, REtiq, rResp: String;
begin
  rEtiq := edEtiqueta.Text;
  rResp := dm.user;
  //inherited;
  str := 'SELECT EOF_STATUS FROM ATS_ETIQOF  WHERE EOF_CODETI = ' +
    QuotedStr(edEtiqueta.Text);  // VER COM O LUCIANO  #########################################################
  ConsultaBase(str);
  if (dm.cdsBusca.IsEmpty) then
  begin
    MessageDlg('ETIQ. INVALIDA', mtWarning, [mbOK],0);
    exit;
  end;

  if (dm.cdsBusca.Fields[0].asInteger = 3) then
  begin
    MessageDlg('JA EMPENHADA', mtWarning, [mbOK],0);
    exit;
  end;

  // Confirma o Recebimento de Material
  str := 'UPDATE ATS_ETIQOF SET EOF_STATUS = 3 WHERE EOF_CODETI = ' +
    QuotedStr(REtiq);
  try
    dm.SQLConnection1.ExecuteDirect(str);

    // Log de Etiquetas
    if (dm.sProcLog.Active) then
      dm.sProcLog.Close;
    dm.sProcLog.ParamByName('CODETI').AsString := REtiq;
    dm.sProcLog.ParamByName('LOGUSU').AsString := RResp;
    dm.sProcLog.ParamByName('HISTOR').AsString := 'ETIQUETA CONFIRMADA PELA PRODUCAO - '+ DateToStr(today);
    Try
      dm.sProcLog.ExecProc;
    except
      {on E: Exception do
      begin
        sMensagem := dm.TraduzErro(E.Message, sMensagem);
        if (sMensagem <> '') then
        begin
          result := sMensagem;
        end
        else begin
          result := 'ERRO LOG';
        end;
      end;}
      MessageDlg('Ja Confirmado.', mtWarning, [mbOK],0);
    end;
    //result := 'OK';
    dm.sProcLog.Close;

  except
    {on E: Exception do
    begin
      sMensagem := dm.TraduzErro(E.Message, sMensagem);
      if (sMensagem <> '') then
      begin
        result := sMensagem;
      end
      else begin
        result := 'ERRO CONF. MATERIAL';
      end;
    end;  }
    MessageDlg('ERRO CONF. MATERIAL', mtWarning, [mbOK],0);
  end;


end;

procedure TfConfirmaRec.btnProcurarClick(Sender: TObject);
begin
  //inherited;

end;

procedure TfConfirmaRec.ConsultaBase(sql: string);
begin
  if (dm.cdsBusca.Active) then
    dm.cdsBusca.Close;
  dm.cdsBusca.CommandText := Sql;
  dm.cdsBusca.Open;
end;

procedure TfConfirmaRec.FormKeyPress(Sender: TObject; var Key: Char);
begin
  //inherited;
 if (key = #13) then
 begin
   btnGravar.Click;
 end;
end;

procedure TfConfirmaRec.edProdutoExit(Sender: TObject);
begin
  if (edProduto.Text <> '') then
  begin

  end;
end;

end.
